from rest_framework import serializers
from dify.models import Report
from users.serializers import UserInfoSerializer

class IndustryReportSerializer(serializers.ModelSerializer):
    """产业报告序列化器"""
    user = UserInfoSerializer(read_only=True)
    workflow_name_display = serializers.SerializerMethodField()

    class Meta:
        model = Report
        fields = ['id', 'title', 'content', 'workflow_name', 'workflow_name_display', 
                 'report_type', 'report_style', 'industry', 'user', 'created_at', 'updated_at']
    
    def get_workflow_name_display(self, obj):
        return obj.get_workflow_name_display()

class IndustryReportListSerializer(serializers.ModelSerializer):
    """产业报告列表序列化器"""
    user = UserInfoSerializer(read_only=True)
    workflow_name_display = serializers.SerializerMethodField()

    class Meta:
        model = Report
        fields = ['id', 'title', 'industry', 'report_type', 'report_style', 
                 'user', 'workflow_name_display', 'created_at']
    
    def get_workflow_name_display(self, obj):
        return obj.get_workflow_name_display()

class IndustryReportCreateSerializer(serializers.ModelSerializer):
    """产业报告创建序列化器"""
    keyword = serializers.CharField(write_only=True)

    class Meta:
        model = Report
        fields = ['keyword']

class IndustryReportUpdateSerializer(serializers.ModelSerializer):
    """产业报告更新序列化器"""
    class Meta:
        model = Report
        fields = ['title', 'content', 'report_type', 'report_style']
        extra_kwargs = {
            'title': {'required': False},
            'content': {'required': False},
            'report_type': {'required': False},
            'report_style': {'required': False}
        }
